/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Control.Controle;
import Model.Aresta;
import Model.Grafo;
import Model.Nodo;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Bernardo
 */
public class Interface extends javax.swing.JFrame {

    private Controle controle; 
    
    /**
     * Creates new form Interface
     */
    public Interface() {
        initComponents(); 
        //desabilito os botoes de criar nó,criar aresta e calcular grafo
        jButtonCriaAresta.setEnabled(false);
        jButtonCriaNo.setEnabled(false);
        jButtonCalcular.setEnabled(false);
        //crio o objeto que irá controlar as operações feitas pelo usuario na interface
        controle = new Controle();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextNomeGrafo = new javax.swing.JTextField();
        jButtonCriaGrafo = new javax.swing.JButton();
        jComboBoxGrafos = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldNomeNo = new javax.swing.JTextField();
        jButtonCriaNo = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldValorNo = new javax.swing.JTextField();
        jComboBoxTipoNo = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldNomeAresta = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldValorAresta = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jComboBoxNoOrigem = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jComboBoxNoDestino = new javax.swing.JComboBox();
        jButtonCriaAresta = new javax.swing.JButton();
        jComboBoxArestasExistentes = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaCustoTotal = new javax.swing.JTextArea();
        jButtonCalcular = new javax.swing.JButton();
        jButtonLimpaInformacoes = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("POO - Trabalho 01 - Alexandre, Bernardo e Daniel - Pós Web 10");
        setResizable(false);

        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel1.setText("Nome do Grafo");

        jTextNomeGrafo.setName(""); // NOI18N

        jButtonCriaGrafo.setText("Criar");
        jButtonCriaGrafo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCriaGrafoActionPerformed(evt);
            }
        });

        jComboBoxGrafos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxGrafosActionPerformed(evt);
            }
        });

        jLabel2.setText("Grafo Selecionado");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Grafos");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jComboBoxGrafos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(26, 26, 26))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                        .addComponent(jTextNomeGrafo, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButtonCriaGrafo)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextNomeGrafo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCriaGrafo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxGrafos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Nós");

        jLabel5.setText("Nome do Nó");

        jButtonCriaNo.setText("Criar");
        jButtonCriaNo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCriaNoActionPerformed(evt);
            }
        });

        jLabel6.setText("Valor do Nó");

        jComboBoxTipoNo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Inicial", "Intermediário", "Final" }));
        jComboBoxTipoNo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxTipoNoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldValorNo, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldNomeNo, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxTipoNo, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCriaNo))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel4)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldNomeNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jTextFieldValorNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxTipoNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCriaNo))
                .addContainerGap())
        );

        jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Arestas");

        jLabel9.setText("Nome da Aresta");

        jLabel10.setText("Valor da Aresta");

        jLabel11.setText("Nó Origem");

        jLabel12.setText("Nó Destino");

        jButtonCriaAresta.setText("Criar");
        jButtonCriaAresta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCriaArestaActionPerformed(evt);
            }
        });

        jLabel13.setText("Arestas cadastradas");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10)
                            .addComponent(jLabel11)
                            .addComponent(jLabel12)
                            .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTextFieldValorAresta, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextFieldNomeAresta)
                                .addComponent(jComboBoxNoOrigem, 0, 115, Short.MAX_VALUE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jComboBoxArestasExistentes, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBoxNoDestino, javax.swing.GroupLayout.Alignment.LEADING, 0, 115, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addComponent(jButtonCriaAresta)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldNomeAresta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldValorAresta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jComboBoxNoOrigem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBoxNoDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButtonCriaAresta)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBoxArestasExistentes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setText("Custo total do Grafo");

        jTextAreaCustoTotal.setColumns(20);
        jTextAreaCustoTotal.setLineWrap(true);
        jTextAreaCustoTotal.setRows(5);
        jScrollPane1.setViewportView(jTextAreaCustoTotal);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
                .addContainerGap())
        );

        jButtonCalcular.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonCalcular.setText("Calcular Grafo");
        jButtonCalcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCalcularActionPerformed(evt);
            }
        });

        jButtonLimpaInformacoes.setText("Limpar Informações");
        jButtonLimpaInformacoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLimpaInformacoesActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setText("Alunos: Alexandre Feustel Baehr - Bernardo Marquardt Müller - Daniel Lenzi");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setText("Pós Web 10 - POO - Trabalho 01");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButtonCalcular)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonLimpaInformacoes)))
                    .addComponent(jLabel14)
                    .addComponent(jLabel15))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonCalcular)
                            .addComponent(jButtonLimpaInformacoes))
                        .addGap(17, 17, 17)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)))
                .addGap(0, 7, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCriaGrafoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCriaGrafoActionPerformed
        if(jTextNomeGrafo.getText()==null || jTextNomeGrafo.getText().isEmpty()){
            JOptionPane.showMessageDialog(this, "Informe um nome para o grafo!", "Erro", JOptionPane.ERROR_MESSAGE);
        }else{
            if(!jButtonCriaNo.isEnabled())
                jButtonCriaNo.setEnabled(true);
            if(jButtonCriaAresta.isEnabled())
                jButtonCriaAresta.setEnabled(false);
            
            Grafo novoGrafo = controle.criaGrafo(jTextNomeGrafo.getText());
        
            jComboBoxGrafos.addItem(novoGrafo);
            jComboBoxGrafos.setSelectedItem(novoGrafo);
            jTextNomeGrafo.setText("");
            jTextAreaCustoTotal.setText("");
        }        
    }//GEN-LAST:event_jButtonCriaGrafoActionPerformed

    private void jButtonCriaNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCriaNoActionPerformed
        //chamo o controle, passando o grafo selecionado no combobox
        //e as informações inseridas do nó
        try{
            if(jTextFieldNomeNo.getText().isEmpty() || jTextFieldValorNo.getText().isEmpty()){
                JOptionPane.showMessageDialog(this, "Preencha os campos do Nó corretamente!", "Erro", JOptionPane.ERROR_MESSAGE);
            } else {
                String nome = jTextFieldNomeNo.getText();
                double valor = Double.parseDouble(jTextFieldValorNo.getText());
                String tipo = (String)jComboBoxTipoNo.getSelectedItem();

                Grafo grafoSelecionado = (Grafo)jComboBoxGrafos.getSelectedItem();        
                    
                Nodo novoNo = controle.adicionaNo(nome,valor, tipo, grafoSelecionado.getIdGrafo());              
                   
                jComboBoxNoOrigem.addItem(novoNo);
                jComboBoxNoDestino.addItem(novoNo);
                
                jTextFieldNomeNo.setText("");
                jTextFieldValorNo.setText("");
                
                if(!jButtonCriaAresta.isEnabled())
                    jButtonCriaAresta.setEnabled(true);
            }       
                     
        } catch(NumberFormatException ex){
            JOptionPane.showMessageDialog(this, "Digite o campo Valor corretamente!", "Erro", JOptionPane.ERROR_MESSAGE);
        
        } catch(NullPointerException e){
            JOptionPane.showMessageDialog(this, "Selecione um grafo!", "Erro", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButtonCriaNoActionPerformed

    private void jButtonCriaArestaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCriaArestaActionPerformed
        try{
            if(jTextFieldNomeAresta.getText().isEmpty() || jTextFieldValorAresta.getText().isEmpty()){
                JOptionPane.showMessageDialog(this, "Preencha os campos de Aresta corretamente!", "Erro", JOptionPane.ERROR_MESSAGE);
            } else {                
                String nome  = jTextFieldNomeAresta.getText();
                double valor = Double.parseDouble(jTextFieldValorAresta.getText());

                Nodo nodoInicial = (Nodo)jComboBoxNoOrigem.getSelectedItem();
                Nodo nodoFinal = (Nodo)jComboBoxNoDestino.getSelectedItem();   
                Grafo grafoSelecionado = (Grafo)jComboBoxGrafos.getSelectedItem();

                Aresta novaAresta = controle.adicionaAresta(nome, valor, nodoInicial, nodoFinal, grafoSelecionado.getIdGrafo());                
                
                jComboBoxArestasExistentes.addItem(novaAresta);
                
                jTextFieldNomeAresta.setText("");
                jTextFieldValorAresta.setText("");
                
                if(jButtonCriaNo.isEnabled()) 
                    jButtonCriaNo.setEnabled(false);
                if(!jButtonCalcular.isEnabled())
                    jButtonCalcular.setEnabled(true);
            }
        }catch(NumberFormatException e){
            JOptionPane.showMessageDialog(this, "Digite o campo Valor corretamente!", "Erro", JOptionPane.ERROR_MESSAGE);
        }          
    }//GEN-LAST:event_jButtonCriaArestaActionPerformed

    private void jComboBoxTipoNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxTipoNoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxTipoNoActionPerformed

    private void jButtonLimpaInformacoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLimpaInformacoesActionPerformed
        this.removeItems(false);
        jButtonCalcular.setEnabled(false);
        jButtonCriaAresta.setEnabled(false);
        jButtonCriaGrafo.setEnabled(true);
        jButtonCriaNo.setEnabled(false);
        controle = null;
        controle = new Controle();
        
        JOptionPane.showMessageDialog(this, "Informações excluídas com sucesso", "Aviso", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_jButtonLimpaInformacoesActionPerformed

    private void jComboBoxGrafosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxGrafosActionPerformed
        Grafo grafo = (Grafo) jComboBoxGrafos.getSelectedItem();
        //atualizar também os ComboBoxes de Nós e Arestas
                
        removeItems(true);
        jTextAreaCustoTotal.setText("");
        
        try {
             if(grafo.possuiAresta()) {
            jButtonCriaAresta.setEnabled(true);
            jButtonCriaNo.setEnabled(false);
            jButtonCalcular.setEnabled(true);
            
            //busco a lista de Arestas, e carrego no Combo
            ArrayList<Aresta> arestas = grafo.getListaAresta();
            
            for(Aresta aresta : arestas) {
                jComboBoxArestasExistentes.addItem(aresta);
            }            
            
        } else {            
            jButtonCriaNo.setEnabled(true);
            jButtonCalcular.setEnabled(false);
        }
        if(grafo.possuiNo()) {
            ArrayList<Nodo> nodoExistentes = grafo.getListaNodo();
            for(Nodo nodo : nodoExistentes) {
                jComboBoxNoOrigem.addItem(nodo);
                jComboBoxNoDestino.addItem(nodo);
            }                
            jButtonCriaAresta.setEnabled(true);
        }                
        else {                
            jButtonCriaAresta.setEnabled(false);
        }                
        
        grafo = null;
        } catch (Exception e) {
            
        }
    }//GEN-LAST:event_jComboBoxGrafosActionPerformed

    private void jButtonCalcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCalcularActionPerformed
        String mensagemCalculo = controle.Calcular((Grafo)jComboBoxGrafos.getSelectedItem());
        jTextAreaCustoTotal.setText(mensagemCalculo);
    }//GEN-LAST:event_jButtonCalcularActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Interface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Interface().setVisible(true);                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCalcular;
    private javax.swing.JButton jButtonCriaAresta;
    private javax.swing.JButton jButtonCriaGrafo;
    private javax.swing.JButton jButtonCriaNo;
    private javax.swing.JButton jButtonLimpaInformacoes;
    private javax.swing.JComboBox jComboBoxArestasExistentes;
    private javax.swing.JComboBox jComboBoxGrafos;
    private javax.swing.JComboBox jComboBoxNoDestino;
    private javax.swing.JComboBox jComboBoxNoOrigem;
    private javax.swing.JComboBox jComboBoxTipoNo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaCustoTotal;
    private javax.swing.JTextField jTextFieldNomeAresta;
    private javax.swing.JTextField jTextFieldNomeNo;
    private javax.swing.JTextField jTextFieldValorAresta;
    private javax.swing.JTextField jTextFieldValorNo;
    private javax.swing.JTextField jTextNomeGrafo;
    // End of variables declaration//GEN-END:variables

    private void removeItems(boolean grafo) {
        if(!grafo) {
            jComboBoxGrafos.removeAll();
            jComboBoxGrafos.removeAllItems();    
        }        
        
        jComboBoxNoOrigem.removeAll();
        jComboBoxNoOrigem.removeAllItems();
        
        jComboBoxNoDestino.removeAll();
        jComboBoxNoDestino.removeAllItems();
        
        jComboBoxArestasExistentes.removeAll();
        jComboBoxArestasExistentes.removeAllItems();
    }
}
